#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
#include <iostream>

int main(){
    int shmfd=shm_open("/ymbxshm",O_CREAT | O_RDWR,0666);
    std::cout<<shmfd<<std::endl;
    if(shmfd<0){
        perror("shm_open error");
        exit(1);
    }
    char* ptr=(char*)mmap(NULL,1024,PROT_READ | PROT_WRITE,MAP_SHARED,shmfd,0);
    if(ptr==(void*)-1){
        perror("mmap error");
        exit(2);
    }

    char buffer[1024];
    while(1){
        memset(buffer,0,sizeof(buffer));
        printf("Enter message:");
        fflush(stdout);
        fgets(buffer,sizeof(buffer)-1,stdin);
        strncpy(ptr,buffer,sizeof(buffer)-1);
        if(strncmp(buffer,"quit",4)==0){
            break;
        }
        sleep(1);
    }

    return 0;
}